#ifndef __BASICBUFFER_HPP_
#define __BASICBUFFER_HPP_

#include <string>
#include "common/network/SharedConstBuffer.hpp"
#include <boost/shared_ptr.hpp>


    namespace network
    {
        namespace buffer
        {

            /**	@class		BasicBuffer
             *	@lang		French
             *	@brief		spÈcialisation de shared_const_buffer pour en simplifier l'utilisation.
             *				A dÈriver pour crÈer des packets.
             */

            /**	@class		BasicBuffer
             *	@lang		English
             *	@brief		Specialization of SharedConstBuffer which implemetn simple buffer, in order to simplify the use.
             *				Derive all packets from BasicBuffer.
             */

            class BasicBuffer :
				public SharedConstBuffer
            {
            protected:

                boost::uint16_t	m_id;
                boost::uint16_t	read_size_;

                explicit BasicBuffer();
                explicit BasicBuffer(boost::uint16_t _size);
                explicit BasicBuffer(boost::uint16_t _size, boost::uint16_t _id);
                explicit BasicBuffer(boost::shared_ptr< std::vector<unsigned char> >& data);
                explicit BasicBuffer(boost::shared_ptr< std::vector<unsigned char> >& data, boost::uint16_t _size);
                explicit BasicBuffer(std::string);
                explicit BasicBuffer(std::string, boost::uint16_t _size);
                
                

            public:

				virtual ~BasicBuffer();


                static BasicBuffer* make(boost::shared_ptr< std::vector<unsigned char> >& _data);
                static BasicBuffer* make(boost::uint16_t _size, boost::uint16_t _id, std::string& _data);
				
				BasicBuffer(const BasicBuffer& _packet);


                template <class T> void make(T _data)
                {
                    put(m_size);
                    put(m_id);
                    put(_data);
                }

                std::vector< unsigned char > & operator*();
                std::size_t			getSize();
                boost::uint16_t		getId();

                void putSize(boost::uint16_t	_size);
                void putId(boost::uint16_t	_id);
                void putData(std::string&	_data);
                void putData(std::string& _data, boost::uint16_t	_size);

                template <class T> BasicBuffer & operator<<(T& _input)
                {
                    put(_input);
                    return *this;
                }

                template <class T> BasicBuffer & operator>>(T& _read_buffer)
                {
                    _read_buffer = get<T > ();
                    return *this;
                }

                virtual void receive_handle()
                {
                };

                virtual void send_handle()
                {
                };

            };

        } // namespace buffer
    } //  // namespace network


#endif // __BASICBUFFER_HPP_
